<?
/*Issue # 2103 Usaepay payment interface
 * Created by:Hossam Fawzallah 12/8/2010
 * 
 * this class responsople for create client and token for payment gateway
 */
/*

This class represent's our adaptor to connect to USAepay Gateway

All you need is to  change  in app.yml:
=============================

				1- $wsdl url
				2- $sourcekey
				3- $pin 
*/
class TokenClient {
 
    public $client; // initialize client
    public $token;// initialize token
 
  public  function __construct(){
      $this->client=self::getClient(); //Using this class
      $this->token=self::getToken();   //Using this class
//print_r($token);
    }
 
    static function getClient(){
        //for live server use 'www' for test server use 'sandbox'
        $wsdl=PGConfiguration::WSDL;
        //'https://sandbox.usaepay.com/soap/gate/15E7FB61/usaepay.wsdl'; 

        return new SoapClient($wsdl,array("trace"=>1,"exceptions"=>1));
        //Must have Php5 compiled with --enable-soap
        //Otherwise use pear soap. For more info please visit: http://pear.php.net/package/SOAP
    }
 
    static function getToken(){
        // Creating a ueSecurityToken
        $sourcekey =PGConfiguration::SOURCE_KEY;//'0QB2S1e1o1N7LUy7C91T9VbBcJU8B6z4';

	//Input your merchant console generated source key
        $pin = PGConfiguration::PIN; //Input the PIN set in the source editor for your source key

        // generate random seed value
        $seed=time() . rand();
 
        // make hash value using sha1 function
        $clear= $sourcekey . $seed . $pin;
        $hash=sha1($clear);
 
        // assembly ueSecurityToken as an array
        // (php5 will correct the type for us)
        $tok=array(
         'SourceKey'=>$sourcekey,
         'PinHash'=>array(
            'Type'=>'sha1',
            'Seed'=>$seed,
            'HashValue'=>$hash
            ),
         'ClientIP'=> '127.0.0.1',
        );
        return $tok;
    }
}